#include <cstdio>
#include <cmath>
#include <algorithm>

using namespace std;

#define eps 1e-8
#define zero(x) (((x)>0?(x):-(x))<eps)

struct point{double x,y;};

double xmult(point p1,point p2,point p0){
    return (p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y);
}

int dot_online_in(point p,point l1,point l2){
    return zero(xmult(p,l1,l2))&&(l1.x-p.x)*(l2.x-p.x)<eps&&(l1.y-p.y)*(l2.y-p.y)<eps;
}

int same_side(point p1,point p2,point l1,point l2){
    return xmult(l1,p1,l2)*xmult(l1,p2,l2)>eps;
}

int dots_inline(point p1,point p2,point p3){
    return zero(xmult(p1,p2,p3));
}

int intersect_in(point u1,point u2,point v1,point v2){
    if (!dots_inline(u1,u2,v1)||!dots_inline(u1,u2,v2))
        return !same_side(u1,u2,v1,v2)&&!same_side(v1,v2,u1,u2);
    return dot_online_in(u1,v1,v2)||dot_online_in(u2,v1,v2)||dot_online_in(v1,u1,u2)||dot_online_in(v2,u1,u2);
}

struct shape
{
    char name, intersect[ 30 ];
    point p[ 30 ];
    int v, i;
};

bool operator < ( const shape &a, const shape &b )
{
    return a.name < b.name;
}

shape s[ 30 ];

bool intersect( shape a, shape b )
{
    int i, j;
    for ( i = 0; i < a.v; i++ )
        for ( j = 0; j < b.v; j++ )
            if ( intersect_in( a.p[ i ], a.p[ ( i + 1 ) % a.v ], b.p[ j ], b.p[ ( j + 1 ) % b.v ] ) )
                return true;
    return false;
}

int main( )
{
    int n, i, j;
    char t[ 200 ];
    while ( 1 )
    {
        n = 0;
        while ( scanf("%s", t) )
        {
            if ( t[ 0 ] == '-' || t[ 0 ] == '.' )
                break;
            s[ n ].name = t[ 0 ];
            scanf("%s", t);
            if ( t[ 0 ] == 's' )
            {
                s[ n ].v = 4;
                scanf(" (%lf,%lf)", &s[ n ].p[ 0 ].x, &s[ n ].p[ 0 ].y);
                scanf(" (%lf,%lf)", &s[ n ].p[ 2 ].x, &s[ n ].p[ 2 ].y);
                s[ n ].p[ 1 ].x = ( s[ n ].p[ 0 ].x + s[ n ].p[ 2 ].x + s[ n ].p[ 2 ].y - s[ n ].p[ 0 ].y ) / 2;
                s[ n ].p[ 1 ].y = ( s[ n ].p[ 0 ].x - s[ n ].p[ 2 ].x + s[ n ].p[ 2 ].y + s[ n ].p[ 0 ].y ) / 2;
                s[ n ].p[ 3 ].x = ( s[ n ].p[ 0 ].x + s[ n ].p[ 2 ].x + s[ n ].p[ 0 ].y - s[ n ].p[ 2 ].y ) / 2;
                s[ n ].p[ 3 ].y = ( -s[ n ].p[ 0 ].x + s[ n ].p[ 2 ].x + s[ n ].p[ 0 ].y + s[ n ].p[ 2 ].y ) / 2;
            }
            if ( t[ 0 ] == 'l' )
            {
                s[ n ].v = 2;
                scanf(" (%lf,%lf)", &s[ n ].p[ 0 ].x, &s[ n ].p[ 0 ].y);
                scanf(" (%lf,%lf)", &s[ n ].p[ 1 ].x, &s[ n ].p[ 1 ].y);
            }
            if ( t[ 0 ] == 'r' )
            {
                s[ n ].v = 4;
                scanf(" (%lf,%lf)", &s[ n ].p[ 0 ].x, &s[ n ].p[ 0 ].y);
                scanf(" (%lf,%lf)", &s[ n ].p[ 1 ].x, &s[ n ].p[ 1 ].y);
                scanf(" (%lf,%lf)", &s[ n ].p[ 2 ].x, &s[ n ].p[ 2 ].y);
                s[ n ].p[ 3 ].x = s[ n ].p[ 0 ].x + s[ n ].p[ 2 ].x - s[ n ].p[ 1 ].x;
                s[ n ].p[ 3 ].y = s[ n ].p[ 0 ].y + s[ n ].p[ 2 ].y - s[ n ].p[ 1 ].y;
            }
            if ( t[ 0 ] == 't' )
            {
                s[ n ].v = 3;
                scanf(" (%lf,%lf)", &s[ n ].p[ 0 ].x, &s[ n ].p[ 0 ].y);
                scanf(" (%lf,%lf)", &s[ n ].p[ 1 ].x, &s[ n ].p[ 1 ].y);
                scanf(" (%lf,%lf)", &s[ n ].p[ 2 ].x, &s[ n ].p[ 2 ].y);
            }
            if ( t[ 0 ] == 'p' )
            {
                scanf("%d", &s[ n ].v);
                for ( i = 0; i < s[ n ].v; i++ )
                    scanf(" (%lf,%lf)", &s[ n ].p[ i ].x, &s[ n ].p[ i ].y);
            }
            n++;
        }
        if ( t[ 0 ] == '.' )
            break;
        sort( s, s + n );
        for ( i = 0; i < n; i++ )
            s[ i ].i = 0;
        for ( i = 0; i < n; i++ )
            for ( j = i + 1; j < n; j++ )
                if ( intersect( s[ i ], s[ j ] ) )
                {
                    s[ i ].intersect[ s[ i ].i++ ] = s[ j ].name;
                    s[ j ].intersect[ s[ j ].i++ ] = s[ i ].name;
                }
        for ( i = 0; i < n; i++ )
        {
            if ( s[ i ].i == 0 )
                printf("%c has no intersections\n", s[ i ].name);
            if ( s[ i ].i == 1 )
                printf("%c intersects with %c\n", s[ i ].name, s[ i ].intersect[ 0 ]);
            if ( s[ i ].i == 2 )
                printf("%c intersects with %c and %c\n", s[ i ].name, s[ i ].intersect[ 0 ], s[ i ].intersect[ 1 ]);
            if ( s[ i ].i > 2 )
            {
                printf("%c intersects with ", s[ i ].name);
                for ( j = 0; j < s[ i ].i - 1; j++ )
                    printf("%c, ", s[ i ].intersect[ j ]);
                printf("and %c\n", s[ i ].intersect[ j ]);
            }
        }
        puts("");
    }
    return 0;
}
